<template>
    <div></div>
</template>
<script>
import ScreenShort from 'js-web-screen-shot'
export default {
    data() {
        return {}
    },
    mounted() {
        this.capture()
    },
    methods: {
        async capture() {
            const returnData = await window.ipcRenderer.invoke('capture')
            const stream = await window.navigator.mediaDevices.getUserMedia({
                audio: false,
                video: {
                    mandatory: {
                        chromeMediaSource: 'desktop',
                        chromeMediaSourceId: returnData.sources[0].id
                    }
                }
            })
            new ScreenShort({
                enableWebRtc: true,
                screenFlow: stream,
                level: 999999,
                canvasWidth: returnData.width,
                canvasHeight: returnData.height,
                completeCallback: this.completeCallback,
                closeCallback: this.closeCallback
            })
        },
        completeCallback(data) {
            window.ipcRenderer.sendSync('close', { type: 'success', data: data })
        },
        closeCallback() {
            window.ipcRenderer.sendSync('close', { type: 'close' })
        }
    }
}
</script>
<style scoped></style>
